a = int(input())
b = str(a)
c = 0
f = 0
j = 0
n = 0
q = 0
t = 0
w = 0
aa = 0
dd = 0
if 999<a<10000:
    k = 0
    for z in range(2, a//2):
        if a % z == 0:
            k +=1
    if k == 0:
        print(a)
    else:
        b1 = int(b[0])
        b2 = int(b[1])
        b3 = int(b[2])
        b4 = int(b[3])
        for i in range(2, int(b[0] + b[1] + b[2])):
            if int(b[0] + b[1] + b[2]) % i == 0:
                c += 1
        if c == 0:
            d = int(b[0] + b[1] + b[2])
        else:
            d = 0

        for e in range(2, int(b[1] + b[2] + b[3])):
            if int(b[1] + b[2] + b[3]) % e == 0:
                f += 1
        if f == 0:
            g = int(b[1] + b[2] + b[3])
        else:
            g = 0

        for h in range(2, int(b[0] + b[1])):
            if int(b[0] + b[1]) % h == 0:
                j += 1
        if j == 0:
            l = int(b[0] + b[1])
        else:
            l = 0

        for m in range(2, int(b[1] + b[2])):
            if int(b[1] + b[2]) % m == 0:
                n += 1
        if n == 0:
            o = int(b[1] + b[2])
        else:
            o = 0

        for p in range(2, int(b[2] + b[3])):
            if int(b[2] + b[3]) % p == 0:
                q += 1
        if q == 0:
            r = int(b[2] + b[3])
        else:
            r = 0



        for s in range(2, b1):
            if b1 % s == 0:
                t += 1
        if t == 0:
            u = b1
        else:
            u = 0

        for v in range(2, b2):
            if b2 % v == 0:
                w += 1
        if w == 0:
            x = b2
        else:
            x = 0

        for y in range(2, b3):
            if b3 % y == 0:
                aa += 1
        if aa == 0:
            bb = b3
        else:
            bb = 0

        for cc in range(2, b4):
            if b4 % cc == 0:
                dd += 1
        if dd == 0:
            ee = b4
        else:
            ee = 0
 
        print(max(d,g,l,o,r,u,x,bb,ee))
else:
    print(0)


